<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改商品</title>
    <style>
        div{
            text-align: center;
            background-color: beige;
            margin: 0 auto;
            padding: 30px;
        }
        input[type="text"]{
            width: 500px;
            height: 50px;
            margin-top: 6px;
        }
    </style>
</head>
<body>
<div>
    <h1>修改商品页面</h1>
    <input type="text" v-model="product.id" placeholder="id" readonly><br>
    <input type="text" v-model="product.title" placeholder="标题"><br>
    <input type="text" v-model="product.price" placeholder="价格"><br>
    <input type="text" v-model="product.saleCount" placeholder="销量"><br>
    <input style="height: 50px;width: 100px;margin-top: 20px" type="button" value="修改" @click="update()">
</div>

<script src="js/vue.js"></script>
<script src="js/axios.min.js"></script>

<script>
    let v = new Vue({
        el:"div",
        data:{
           product:{}
        },
        created: function(){
            //得到地址栏的id参数
            let id = location.search.split("=")[1];
            //根据得到的id查询对应的商品信息
            axios.get("/selectByid?id="+id).then(function (response){
                //把查询回来的数据赋值给product对象
                v.product=response.data;
            })
        },
        methods:{
            update(){
                axios.post("/update",v.product).then(function (){
                    alert("修改成功!");
                    location.href="/list.html";
                })
            }
        }
    })
</script>
</body>
</html>